import { ref } from 'vue';

export const useImport = (options = {}) => {
  const {
    importApi, // 导入API函数
    afterSuccess, // 导入成功后的回调
    types = ['xlsx'], // 允许的文件类型
  } = options;

  const importConfig = ref({
    remote: true,
    types,
    async importMethod({ file, options: importOptions }) {
      try {
        await importApi({ file, options: importOptions });
        afterSuccess?.();
      } catch (error) {
        console.error('导入失败:', error);
        throw error; // 抛出错误以便 vxe-grid 显示错误信息
      }
    },
  });

  return { importConfig };
};
